var szCreatingDivs = new String();
var MaxShownCharacters = 40;
var templateTags;
var Err = 0;

function shine(elId,shineColor)
{

//	document.all[elId].style.backgroundColor = shineColor;

	document.all[elId].style.color = shineColor;
}

function caseShine (bCase,elID,shineColor)
{
	if (bCase)
	{
		shine(elID,shineColor)
	}
}

function initSpecTags(tagName)
{
	return document.all.tags(tagName);
}

function show_tags()
{
	if (templateTags.length == 0 )
	{
		return 0;
	}
	else
	{
		for (var i=0; i < templateTags.length; i++)
		{
			constructHTML2(templateTags[i]);
			Err = show_tags();
		}
		return Err;
	}
}

// ::
function constructHTML2(templateElement)
{
	var correctAttr;
	var flsrc;
	correctAttr = false;
	flsrc = "";
	var magicString;
	magicString = templateElement.getAttribute('id');
	for (i in top.aMagicString)
	{
		if ( magicString == top.aMagicString[i] )
		{
			correctAttr = true;
		}
	}
	if (correctAttr == false)
	{
	}
	if (magicString.indexOf('img_') == 0) 
	{
		var imgurl = top.aMagicString2[magicString];
		templateElement.outerHTML = "<img src='"+imgurl+"' border='0' ondrag='return false;'>";
	}
	else
	{
		if (magicString == "background")
		{
			templateElement.outerHTML = "";
			var imgurl = top.aMagicString2[magicString];
			document.body.background = imgurl;
		}
		else
		{
			templateElement.outerHTML = top.aMagicString2[magicString];
		}
	}
}

// ::
function PB_Cursor(szCursor)
{
	//!... change to state change event catching
	
	document.all["scenario2"].style.cursor = szCursor;
}				


function ShowProgressBar()
{
	//HideAlertDiv();
	//HideAlert2Div();
	//HideSelects();
	
	document.all["scenario2"].style.visibility = "visible";
}


function HideAlert2Div()
{
	document.all["alertdiv2"].style.visibility = "hidden";
	
	//ShowSelects();
	//ShowScenarioButtons();
}

function HideAlertDiv()
{
	document.all["alertdiv"].style.visibility = "hidden";
	
	//ShowSelects();
	//ShowScenarioButtons();
}

function HideProgressBar()
{
	document.all["scenario2"].style.visibility = "hidden";
	
	//ShowSelects();
}

function caseCursor(bCase, elID, szCursor)
{

//if IE6

	if (bCase)
	{
		document.all[elID].style.cursor = szCursor;
	}
}

function focus_(eID, regDiv)
{

	//if (typeof document.all[eID] != "undefined")
	
	// [-] AG 040715 : STOPPED
	
	if (regDiv == 1)
	{
		document.all["RegData_1"].style.visibility = "visible";
		document.all["RegData_2"].style.visibility = "hidden";
		document.all["RegData_3"].style.visibility = "hidden";
	}
	if (regDiv == 2)
	{
		document.all["RegData_2"].style.visibility = "visible";
		document.all["RegData_1"].style.visibility = "hidden";
		document.all["RegData_3"].style.visibility = "hidden";
	}
	if (regDiv == 3)
	{
		document.all["RegData_3"].style.visibility = "visible";	
		document.all["RegData_1"].style.visibility = "hidden";
		document.all["RegData_2"].style.visibility = "hidden";
	}
	
	
	// [-] AG 040715 : STOPPED - !
	//top.WaitFocus
	
	setTimeout("document.all['"+eID+"'].focus();",500);
}

function hideLangDiv()
{

	//document.all["scenario_langs"].style.visibility = "hidden";

}

function highlight_banner ( k, bHighLight)
{
	if (typeof document.all["l_" + k] == "object")
	{
		if (bHighLight)
		{
			document.all["l_" + k].src = "../images/head_" + top.aLangs[k] + "-over.jpg";
		}
		else
		{
			document.all["l_" + k].src = "../images/head_" + top.aLangs[k] + ".jpg";
		}
	}
}

function createAppDiv()
{
	szCreatingDivs = '<DIV onselect="return false;" id="scenario3" style="position:absolute; top:1px; left:578px; visibility:visible; width:21; height:21; border:0; scroll:none; cellpadding:0; cellspacing:0; margin:0;">';
	szCreatingDivs += '<IMG tabindex="107" src="../images/_close_1.gif" id="btn_hta_close" border="0" onfocus="fadeoff();" onclick="top.hta_close();	window.event.cancelBubble = true;	" onkeydown="if (window.event.keyCode == 13) {top.hta_close();}" ondrag="return false;"></DIV>';
	szCreatingDivs += '<DIV id="scenario_langs" align="left" style="border:0; position:absolute; top:24; left:262; text-align:left; visibility: hidden; width=44; height=140; scroll:none; overflow:hidden; cellpadding:2; cellspacing:0; margin:0;">';
	szCreatingDivs += '<TABLE border="0" cellspacing="1" cellpadding="0" height="20" style="border: 2px solid #D1D2D4" bgColor="#FFFFFF">';

	for (k = 1; k < top.aLangs_.length; k++)
	{
	
	// do not show russian

		if (k != 6)
		{
			if (top.aLangs_[top.aLangs2[k]] == true)
			{
				if (top.aLangs2[k] == top.sessVars["llanguage_selected"])
				{
					szCreatingDivs += '<TR height="20"><TD  id="lltd_' + top.aLangs2[k] + '" width="30" align="left" alt="' + top.messages[top.aLangs[top.aLangs2[k]]] + '"><IMG src="../images/head_' + top.aLangs[top.aLangs2[k]] + '-over.jpg" id="l_' + top.aLangs2[k] + '" hspace="3" ondrag="return false;" title = "' + top.messages[top.aLangs[top.aLangs2[k]]] + '"></TD></TR>';
				}
				else
				{
					szCreatingDivs += '<TR height="20"><TD id="lltd_' + top.aLangs2[k] + '" width="30" align="left" onclick="if (top.sessVars[\'task\'] == 0) {highlight_banner(' + top.sessVars["llanguage_selected"] + ', 0); top.newlang(' + top.aLangs2[k] + '); swaplanguages();}" alt="' + top.messages[top.aLangs[top.aLangs2[k]]] + '" onmouseover="highlight_banner(' + top.aLangs2[k] + ',1);" onmouseout="highlight_banner(' + top.aLangs2[k] + ',0);"><IMG src="../images/head_' + top.aLangs[top.aLangs2[k]] + '.jpg" id="l_' + top.aLangs2[k] + '" hspace="3" ondrag="return false;" title = "' + top.messages[top.aLangs[top.aLangs2[k]]] + '"></TD></TR>';
				}
			}
			else
			{
				if (top.sessVars["show_unavailable_langs"])
				{
					szCreatingDivs += '<TR height="20"><TD id="lltd_' + top.aLangs2[k] + '" width="30" align="center" alt="' + top.messages[top.aLangs[top.aLangs2[k]]] + '"><IMG src="../images/head_' + top.aLangs[top.aLangs2[k]] + '.jpg" id="l_' + top.aLangs2[k] + '" hspace="3" ondrag="return false;" title = "' + top.messages[top.aLangs[top.aLangs2[k]]] + '"></TD></TR>';
				}
			}
		}	
	}
	szCreatingDivs += '</TR></TABLE></DIV>';
	document.body.innerHTML = document.body.innerHTML + szCreatingDivs;
	
//q'1
//	document.all["btn_hta_drag"].alt = top.messages["btn_hta_drag_cant_drag"];

	document.all["btn_hta_close"].alt = top.messages["btn_hta_close_can_close"];
}

function swaplanguages()
{
	if (document.all["scenario_langs"].style.visibility == "hidden")
	{
		document.all["scenario_langs"].style.visibility = "visible";
	}
	else
	{
		document.all["scenario_langs"].style.visibility = "hidden"
	}
}

function createProgressBar()
{
	szCreatingDivs = "<DIV onselect='return false;' id=scenario2 align=center style='border:0; position:absolute; top:24; left:260; visibility:hidden; width=338; height=170; text-align:center; scroll:yes; cellpadding:2; cellspacing:0; margin:0;'>";
	szCreatingDivs += "<TABLE border=0 bgcolor='#D1D2D4' style='border: #012D6A 2px solid; ' cellspacing=0 cellpadding=0 height=170 width=336>";

	szCreatingDivs += "<TR height=54><TD width=336 align=left bgcolor='#012D6A' id=installation_state colspan=2 style='color: white; font-size:12px; padding: 0 0 0 20;' class=info_txt></font></td></tr>";
	szCreatingDivs += "<TR height=26><TD width=336 align=right bgcolor='#D1D2D4'><img src='../images/t1x1.gif' height=26 width=336 border=0></td></tr>";
	szCreatingDivs += "<TR height=21><TD width=336 align=center bgcolor='#D1D2D4'><table border=0 cellpadding=0 cellspacing=0 height=21 width=300><tr><td><img src='../images/t1x1.gif' width=250 height=1></td></tr><tr><td background='../images/progress_2.gif' align=right><img id=allprogress_bar_img2 src='../images/progress_1.gif' border=0 style='border: 0px solid #000000;' ondrag='return false;' width=300 height=20></td></tr></table></td></tr>";
	szCreatingDivs += "<TR id=progress_2 height=20><td width=336 align=right id=allprogress_bar_value class=info_txt bgcolor='#D1D2D4' style='font-weight:bold; font-size:16px; color:white; padding: 0 40 0 0 ;'></td></TR>";
	szCreatingDivs += "<TR><TD width=336 align=center bgcolor='#D1D2D4'><INPUT id='progressbar_btn' type=button value='" + top.messages["Cancel"] + "' class=alert_btn onclick='top.cancel_install();'>&nbsp;</td></tr>";
	szCreatingDivs += "</table></DIV>";
	document.body.innerHTML = document.body.innerHTML + szCreatingDivs;
	document.all["scenario2"].style.cursor = "default";
}

function lightoff_() { }

function createAlertDiv()
{
	szCreatingDivs = "<DIV id=alertdiv align=center style='border:0; position:absolute; top:24; left:260; text-align:center; visibility:hidden; width=340; height=170; scroll:yes; cellpadding:2; cellspacing:0; margin:0;'>";
	szCreatingDivs += "<TABLE border=0 bgcolor=#D1D2D4 style='border: #012D6A 2px solid; ' cellspacing=1 cellpadding=4 width=340 height=170>";
	szCreatingDivs += "<TR><TD width=340 align=center><p id=alertdiv_mess class=info_txt><b></b></p></td></tr>";
	szCreatingDivs += "<TR><TD width=340 align=center><input id=alertdiv_btn type=button class='alert_btn' value=''></td></tr>";
	szCreatingDivs += "</TABLE></DIV>";
	document.body.innerHTML = document.body.innerHTML + szCreatingDivs;
}

function createAlert2Div()
{
	szCreatingDivs = "<DIV id=alertdiv2 align=center style='border:0; position:absolute; top:24; left:260; text-align:center; visibility:hidden; width=340; height=170; scroll:yes; cellpadding:2; cellspacing:0; margin:0;'>";
	szCreatingDivs += "<table border=0 bgcolor=#D1D2D4 style='border: #012D6A 2px solid; ' cellspacing=1 cellpadding=4 width=340 height=170>";
	szCreatingDivs += "<tr><td width=340 align=center colspan=2><p id=alertdiv2_mess class=info_txt></p></td></tr>";
	szCreatingDivs += "<tr><td width=340 align=center><input id=alertdiv2_btn1 type=button value='" + top.messages["Yes"] + "' ' class='alert_btn'></td>";
	szCreatingDivs += "<td width=340 align=center><input id=alertdiv2_btn2 type=button value='" + top.messages["No"] + "' class='alert_btn'></td></tr></table></DIV>";
	document.body.innerHTML = document.body.innerHTML + szCreatingDivs;
}

function createAlert2Div_() {}

function document_onkeydown() {}

function showmanual() {}

function goInstallFiles() {}

function goInstallFiles2() {}

function goUpdate() {}

function HideDivs() {}

function ShowAlertDiv(szMess,szRun, szTtl)
{
	top.HideSelects();

	//top.HideScenarioButtons();

	top.szContinueWith = szRun;	
	document.all["alertdiv_mess"].innerText = szMess;
	document.all["alertdiv_btn"].value=szTtl;
	document.all["alertdiv_btn"].onclick=top.setTimeout_;
	document.all["alertdiv"].style.visibility = "visible";
}

function ShowAlert2Div(szMess,szRun1,szRun2,szTtl1,szTtl2)
{
	top.HideSelects();

	//HideScenarioButtons();

	document.all["alertdiv2_mess"].innerText = szMess;
	top.szContinueWith1 = szRun1;
	top.szContinueWith2 = szRun2;
	document.all["alertdiv2_btn1"].onclick=top.setTimeout_1;
	document.all["alertdiv2_btn2"].onclick=top.setTimeout_2;
	document.all["alertdiv2_btn1"].value=szTtl1;
	document.all["alertdiv2_btn2"].value=szTtl2;
	document.all["alertdiv2"].style.visibility = "visible";
}

function PB_Action(szAction)
{
	document.all["progressbar_btn"].onclick = szAction;
}

function PB_BtnLabel(szLabel)
{
	document.all["progressbar_btn"].value = szLabel;
}

function PB_State(propState,szStateText)
{
	if ((propState == "src") || (propState == "dest") || (propState == "state"))
	{
		if (propState == "src")
		{

			//document.all["src_bar_value"].title = szStateText;

			// [*] AG 040715 : commented 4 new design
			//document.all["progress_1"].title = szStateText;

			//document.all["src_bar_value"].innerText = top.prepareShortedString(szStateText, MaxShownCharacters);

		}
		if (propState == "dest")
		{
		
		// [*] AG 040715 : commented 4 new design
		//	document.all["dest_bar_value"].title = szStateText;
		//	document.all["dest_bar_value"].innerText = top.prepareShortedString(szStateText, MaxShownCharacters);
		
			document.all["progress_2"].title = szStateText;
		}
		if (propState == "state")
		{
			document.all["installation_state"].innerText = szStateText;
		}
	}
}

function PB_All(iPercentage)
{
	document.all["allprogress_bar_value"].innerText = iPercentage + "%";

	document.all["allprogress_bar_img2"].style.width = 3 * ( 100 - iPercentage ); 

	//document.all["allprogress_bar_img2"].style.width = 2 * iPercentage;
}

function PB_Qvant(iPercentage)
{

// if-s removed to increase representation.
// supposing that in this release progress_bar_value & exists on every page
//	if (typeof document.all["progress_bar_value"] != "undefined")
//	{

// [*] AG 040715 : commented 4 new design
//		document.all["progress_bar_value"].innerText = iPercentage + "%";

//	}
//	if (typeof document.all["progress_bar_img2"] != "undefined")
//	{
//document.all["progress_bar_img1"].style.width = 2 * ( 100 - iPercentage );


// [*] AG 040715 : commented 4 new design
//		document.all["progress_bar_img2"].style.width = 2 * iPercentage;

//	} 

}

function PB_Qvant_general(iPercentage)
{

// if-s removed to increase representation.
// supposing that in this release progress_bar_value & exists on every page


// [*] AG 040715 : commented 4 new design
/*
	if (typeof document.all["progress_bar_value"] != "undefined")
	{
		document.all["progress_bar_value"].innerText = iPercentage + "%";
	}
	if (typeof document.all["progress_bar_img2"] != "undefined")
	{

		//document.all["progress_bar_img1"].style.width = 2 * ( 100 - iPercentage );

		document.all["progress_bar_img2"].style.width = 2 * iPercentage;
	} 
	
*/
	
}

function fadeoff()
{
	for (i=0; i < 7; i++)
	{
		if (typeof document.all["td"+i] != "undefined")	{	shine("td"+i,"#D1D2D4")	}
	}
}

function setPnD( a, b )
{
	return true;
}

function DropState()
{
	if (top.sessVars["installation_status"] = top.iDone)
	{
		if ((top.IE6) && (typeof document.all["a_install"] == "object"))
		{
			document.all["a_install"].style.cursor = "not-allowed";
		}
		if (typeof document.all["a_mail"] == "object")
		{
			document.all["a_mail"].style.cursor = "default";
		}
	}
}

function focusOn_(regName, inputName, regDiv)
{
/*new - at*/
var str;

	if (regName == "EMail")
	{
		str = top.ThrowRegData("EMail");
		if (!top.testEmail(str))
		{
			focus_(inputName, regDiv);
			return false;
		}
	return true;
	};

	if ( (regName == "DateOfPurchase") || (regName == "DateOfRegistration"))
	{
		str = top.ThrowRegData(regName)
		if (str == "")
		{
		str = document.form_RegistrationData.elements[inputName].value;
		}
		if (!testDate(str))
		{
			focus_(inputName, regDiv);
			return false;
		}
		else
		{
		return true;
		}
	}

/*end of "new - at"*/

	if (top.ThrowRegData(regName) == "" )
	{
		focus_(inputName, regDiv);
		return false;
	}
	return true;
}

// ::
function focusOn()
{
	if (!focusOn_("Name", "reg_Name", 1)) return;
	if (!focusOn_("Address", "reg_Address", 1)) return;
	if (!focusOn_("PostalCode", "reg_PostalCode", 1)) return;
	if (!focusOn_("City", "reg_City", 1)) return;
	if (!focusOn_("Country", "reg_Country", 1)) return;
	if (!focusOn_("PhoneNo", "reg_PhoneNo", 1)) return;
	if (!focusOn_("Email", "reg_Email", 1)) return ;
	if (!focusOn_("SerialNo", "reg_SerialNo", 2)) return;
	if (!focusOn_("DateOfPurchase", "reg_DateOfPurchase", 2)) return;
	if (!focusOn_("StoreName", "reg_StoreName", 2)) return;
	if (!focusOn_("StoreCity", "reg_StoreCity", 2)) return;
	if (!focusOn_("DateOfRegistration", "reg_DateOfRegistration", 2)) return;
}

// ::
function Scenario_ (szTask, bKeyDown)
{
	if ((bKeyDown == false) || ((bKeyDown == true) && (window.event.keyCode == 13)))
	{
		switch (szTask)
		{
			case "languages":
				if ((top.sessVars["task"] == 0) && (top.oSwSetup.object.State == top.sIdle))
				{
					swaplanguages();
				}
			break;
			case "install":
				if ((top.sessVars['task'] == 0) && (top.oSwSetup.object.State == top.sIdle))
				{
					top.goInstallFiles2();
					if (bKeyDown)
					{
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
				}
			break;
			case "update":
				if ((top.sessVars["task"] == 0) && (top.oSwSetup.object.State == top.sIdle))
				{
					top.runUpdate();
				}
				window.event.cancelBubble = true;
				window.event.returnValue = false;
			break;
			case "go2register":
				if (top.sessVars["task"] == 0)
				{
					if (top.sessVars["passedBenefitsWindow"] == true)
					{
						top.JumpToRegisterPage();
					}
					else
					{
						top.JumpToBenefitsPage();
					}
				}
			break;
			case "www":
				top.sessVars["www_loaded"]++;
				window.open("http://www.sitecom.com","sitecom"+top.sessVars["www_loaded"],"");
			break;
			case "manual":
				top.showmanual();
				if (bKeyDown)
				{
					window.event.cancelBubble = true;
					window.event.returnValue = false;
				}
			break;
			case "register":
				if (top.sessVars["task"] == 0)
				{
					RegisterDevice();
					top.RegisterResponse();
				}
			break;
			case "go2main":
				if (top.sessVars['task'] == 0)
				{
					
					// [*] AG 040715 : 
					//top.RegOrJump(-1);
					top.RegOrJump(-2);
					
					//top.JumpToMainPage();
				}
			break;
			case "skipReg":
				if (top.sessVars['task'] == 0)
				{
					top.skipReg();
				}
			break;
		}
	}
}

// ::
function highlightScenario(szTask)
{
	switch (szTask)
	{
		case "install":
			return ((top.sessVars['installation_status'] != top.iDone) && (top.oSwSetup.object.State == top.sIdle) && (top.sessVars['task'] == 0));
		break;
		case "not-install":
			return ((top.sessVars['installation_status'] == top.iDone) || (top.oSwSetup.object.State != top.sIdle) || (top.sessVars['task'] != 0));
		break;
		case "update":
			return ((top.oSwSetup.object.State == top.sIdle) && (top.sessVars["task"] == 0));
		break;
		case "go2register":
			return ((top.sessVars["can_register"] == true) && (top.sessVars["task"]==0));
		break;
//updated  10oct04
		case "manual":
			return ((top.sessVars["manual_present"] == true) && (top.sessVars["wait_for_click"] == false));
		break;
		case "software":
			return (typeof top.aMagicString2["software_file"] != "undefined");
		break;
	}
}